package com.lxyk.service.statistic.impl;

import com.lxyk.dao.statistic.ClassAttendanceDao;
import com.lxyk.dao.user.ClassesDao;
import com.lxyk.domain.ClassAttendance;
import com.lxyk.domain.ClassStatisticBO;
import com.lxyk.domain.Classes;
import com.lxyk.domain.SysUser;
import com.lxyk.service.statistic.ClassAttendanceService;
import com.lxyk.service.user.UserService;
import com.lxyk.utils.StatisticUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.*;

//班级数据统计
@Service
public class ClassAttendanceServiceImpl implements ClassAttendanceService {
    @Autowired
    private ClassesDao classesDao ;
    @Autowired
    private ClassAttendanceDao classAttendanceDao;
    @Autowired
    private UserService userService;
    //班级每个月统计数据
    @Override
    public List<ClassStatisticBO> findData(Integer cid) {
        //根据班级id查询班级信息
        return classAttendanceDao.findAvgDate(cid);
//        Classes classes = classesDao.findById(cid);
//        Date openTime = classes.getOpenTime();
//        Date closeTime = classes.getCloseTime();
//        //获取所有年月
//        HashMap<Integer, List<String>> months = StatisticUtils.getMonths(openTime, closeTime);
//        //创建List集合,保存所有的月统计数据
//        ArrayList<ClassStatisticBO> data = new ArrayList<>();
//        //遍历所有的年/月
//        Set<Map.Entry<Integer, List<String>>> entries = months.entrySet();
//        for (Map.Entry<Integer, List<String>> entry : entries) {
//            //当前年
//            Integer year = entry.getKey();
//            //当前年所有月份
//            List<String> allMonth = entry.getValue();
//            //遍历所有月份
//            for (int i = 0; i < allMonth.size(); i++) {
//                //当前月
//                String month = allMonth.get(i);
//                //查询每个月平均到课率/平均作业率
//                ClassStatisticBO avgDate = classAttendanceDao.findAvgDate(cid, year, Integer.valueOf(month));
//                data.add(avgDate);
//            }
//        }
    }

    //班级某个月统计数据
    public List<ClassAttendance> findDayDate(Integer cid,Date date){
        return classAttendanceDao.findDayDate(cid, date);
    }

    //查询当前用户关联班级最新的统计数据
    @Override
    public List<ClassAttendance> findLastData() {
        //得到当前用户用户名
//        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        //根据用户名查询用户信息
//        SysUser user = userService.findByName(username);
        return classAttendanceDao.findLastData();
    }


}
